import Vue from 'vue'
import Vuex from 'vuex'
import { playMode } from './common/config'

Vue.use(Vuex)

export default new Vuex.Store({

  state: {
    singer: {},
    playing: -1,
    fullScreen: false,
    playList: [],
    sequenceList: [],
    mode: playMode.sequence,
    currentIndex: -1,
  },

  getters: {
    currentSong(state) {
      return state.playList[state.currentIndex] || {};
    }
  },

  mutations: {
    setSinger(state, payload) {
      state.singer = payload;
    },

    setPlayStatus(state, flag) {
      state.playing = flag;
    },

    setFullScreen(state, flag) {
      state.fullScreen = flag;
    },

    setPlayList(state, list) {
      state.playList = list;
    },

    setSequenceList(state, list) {
      state.sequenceList = list;
    },

    setMode(state, mode) {
      state.mode = mode;
    },

    setCurrentIndex(state, index) {
      state.currentIndex = index;
    }
  },

  actions: {
    selectPlay({commit, status}, {list, index}) {
      commit('setPlayList', list);
      commit('setSequenceList', list); 
      commit('setPlayStatus', 1); 
      commit('setFullScreen', true); 
      commit('setCurrentIndex', index);   
    }            
  }

})
